package com.sentrix.auto.printercenter.infrastructure.event;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class GuavaEventPublisher implements EventPublisher {
    @Resource(name = "sync-event-bus")
    private EventBus syncEventBus;
    @Resource(name = "async-event-bus")
    private AsyncEventBus asyncEventBus;


    @Override
    public void publish(Object event) {
        // 同步发布：事件处理完成后才返回
        syncEventBus.post(event);
    }

    @Override
    public void publishAsync(Object event) {
        // 异步发布：提交到线程池后立即返回
        asyncEventBus.post(event);
    }
}
